package myTest;
import java.io.*;

public class busMap{
	static String[] station;
	static String[] bus;
	static int[][] busMap;
	
	public static int locationOfStation(String str){
		int i=0;
		while(station[i]!=null){
			if(station[i].compareTo(str)==0)
				return i;
			i++;
		}
		return -1;
	}
	
	public static void main(String[] args){
		busMap=new int[328][2582];
		String busANDstationFile="C:\\Users\\ChengXin\\Desktop\\busANDstation.txt";
		String busFile="C:\\Users\\ChengXin\\Desktop\\bus.txt";
		String busMapFile="C:\\Users\\ChengXin\\Desktop\\busMap.txt";
		try{
			String s;
			BufferedReader in=new BufferedReader(new FileReader(busANDstationFile));
			s=in.readLine();
			s=in.readLine();
			bus=s.split(" ");
			s=in.readLine();
			station=s.split(" ");
			
			int row=0;
			in=new BufferedReader(new FileReader(busFile));
			while((s=in.readLine())!=null){
				String array[]=s.split(" ");
				int i;
				for(i=1; i<(array.length-1); i++)
					busMap[row][locationOfStation(array[i])]=locationOfStation(array[i+1]);
				busMap[row][locationOfStation(array[i])]=locationOfStation(array[1]);
				row++;
			}
			
			FileOutputStream out=new FileOutputStream(busMapFile);
			BufferedWriter buffWriter = new BufferedWriter(new OutputStreamWriter(out));
			for(int i=0; i<busMap.length; i++){
				for(int j=0; j<busMap[0].length; j++)
					buffWriter.write(busMap[i][j]+" ");
				buffWriter.write("\r\n");
			}
			buffWriter.flush();
		}
		catch(Exception e){
			System.out.println(e.toString());
		}
	}
}